<template>
	<view class="content">
		<view class="tishi">设置签名，让更多人了解你</view>
		<view class="inputbkc">
			<textarea class="textarea" auto-height maxlength=500  v-model="signature"/>
		</view>
		<view>
			<button class="btn" @click="setqianming()">确定</button>			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid: '',
				signature: '', // 个性签名
			}
		},
		onLoad(option) {
			this.uid = option.uid;
			this.signature = option.signature;
		},
		methods: {
			setqianming() {
				// 设置个性签名
				uni.request({
					url: 'https://www.yedushu.cn/api/saveqianming', // 保存设置的签名
					method:'POST',
					data: {
						uid: this.uid,
						signature: this.signature
					},
					success: (res) => {
						// console.log(JSON.stringify(res.data.code));
						if(res.data.code == 1) {
							// 修改成功
							var userinfo = uni.getStorageSync('userinfo');
							// console.log(JSON.stringify(userinfo));
							userinfo['attrib']['signature'] = this.signature; // 设置对象中的值
							uni.setStorageSync('userinfo', userinfo);  // 重新存储到本地
							// console.log(JSON.stringify(userinfo));
							// 触发资料与帐号设置（setmyselft.vue）页上的事件，更新用户个性签名
							uni.$emit("setqianming",{
									qianming: this.signature,
								},
							);
							// 返回到上一页面
							uni.navigateBack({
							    delta: 1
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		padding: 10px 10px;
	}
	.tishi {
		padding: 5px 7px;
		color: #b2b2b2;
		font-size: 14px;
	}
	.inputbkc {
		margin: 10px 7px;
		border: 1px solid #b2b2b2;
		padding: 7px 7px;
		border-radius: 7px;
	}
	.textarea {
		min-height: 60px;
		font-size: 14px;
	}
	.btn {
		background-color: #00cc33;
		color: #FFFFFF;
	}
</style>
